package com.icbc.dccsh.util;

import java.io.Serializable;

public class Watcher implements Serializable{
	private String _watcherName;
	private int _counter = 0;
	private Watcher(String watcherName){
		this._watcherName = watcherName;
		this._counter = 0;
	}
	
	public void count(){
		this._counter ++;
		if (this._counter > 39000){
			long threadId = Thread.currentThread().getId();
			System.out.println(String.format("[Thread-%d] [%s] %s records went through...", threadId, this._watcherName, this._counter));
		}
		if (this._counter % Constants.COUNTER_THRESHOLD == 0){
			long threadId = Thread.currentThread().getId();
			System.out.println(String.format("[Thread-%d] [%s] %s records went through...", threadId, this._watcherName, this._counter));
		}
	}
	public static Watcher getWatcher(String clazzName){
		Watcher w  = new Watcher(clazzName);
		return w;
	}
	public static Watcher getWatcher(Class clazz){
		return new Watcher(clazz.getName());
	}
}
